#ifndef __Ogre7zArchive_H__
#define __Ogre7zArchive_H__
#pragma once

// Include stuff
#include "Ogre7zPrerequisites.h"
#include <OgreArchive.h>

#include <7z.h>
#include <7zFile.h>

namespace Ogre
{
	/**
	 * @brief Specialisation of the Archive class to allow reading of files from a 7z format source archive
	 */
	class SevenZipArchive : public Archive
	{
	public:
		/**
		 * @brief Standart constructor
		 */
		SevenZipArchive( const String& name, const String& archType );

		/**
		 * @brief Virtual destructor
		 */
		virtual ~SevenZipArchive();

		/**
		 * @brief Overridden from Archive::isCaseSensitive
		 * @copydoc Archive::isCaseSensitive
		 */
		bool isCaseSensitive() const;

		/**
		 * @brief Overridden from Archive::load
		 * @copydoc Archive::load
		 */
		void load();

		/**
		 * @brief Overridden from Archive::unload
		 * @copydoc Archive::unload
		 */
		void unload();

		/**
		 * @brief Overridden from Archive::open
		 * @copydoc Archive::open
		 */
		DataStreamPtr open(const String& filename, bool readOnly = true) const;

		/**
		 * @brief Overridden from Archive::list
		 * @copydoc Archive::list
		 */
		StringVectorPtr list(bool recursive = true, bool dirs = false);

		/**
		 * @brief Overridden from Archive::listFileInfo
		 * @copydoc Archive::listFileInfo
		 */
		FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);

		/**
		 * @brief Overridden from Archive::find
		 * @copydoc Archive::find
		 */
		StringVectorPtr find(const String& pattern, bool recursive = true, bool dirs = false);

		/**
		 * @brief Overridden from Archive::exists
		 * @copydoc Archive::exists
		 */
		bool exists(const String& filename);

		/**
		 * @brief Overridden from Archive::getModifiedTime
		 * @copydoc Archive::getModifiedTime
		 */
		time_t getModifiedTime(const String& filename);

		/**
		 * @brief Overridden from Archive::findFileInfo
		 * @copydoc Archive::findFileInfo
		 */
		FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true, bool dirs = false);

	protected:
		/**
		 * @brief Retrieves the index of file specified
		 * @return Returns the file index if file exist. Otherwise return (-1)
		 */
		size_t getFileIndex( const String& name ) const;

	protected:
		/// The auto mutex
		OGRE_AUTO_MUTEX

		/// The archive initialisation flag
		bool mInitialised;
		/// The instance of 7zip archive file
		SevenZipFile* m7ZipFile;
		/// File list
		FileInfoList mFileList;
	};

} // end of namespace Ogre

#endif // include guard, end of #ifndef __Ogre7zArchive_H__
